package server.map;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import server.utility.Id;
import server.utility.Point2d;

public class Platform implements Serializable{

	private static final long serialVersionUID = 1L;
	private Id id;
	private Point2d top, bottom;
	
	public Platform(Point2d t, Point2d b){
		id=Id.nextId();
		
		top=t;
		bottom=b;
	}
	
	
	private void readObject(ObjectInputStream in) throws IOException,
	ClassNotFoundException {
		int ver=in.readInt();
		
		switch(ver){
		
			case 1:{
				top = (Point2d)in.readObject();
				bottom = (Point2d)in.readObject();
				id = (Id)in.readObject();
			}
		}
	}
	
	private void writeObject(ObjectOutputStream out) throws IOException {
		out.writeInt(1); //version
		
		out.writeObject(top);
		out.writeObject(bottom);
		out.writeObject(id);		
	}


	public boolean isPosed(Point2d p) {
		boolean inX=p.getX()>=top.getX() && p.getX()<=bottom.getX();
		boolean inY=p.getY()>=top.getY() && p.getY()<=top.getY()+20;
		
		return inX && inY;
	}


	public int getTopY() {
		return top.getY();
	}

}
